package ModelLayer;

import java.util.*;

public class DVD
{
    private long id;
    private String title;
    private String artist;
    private String releaseDate;
    private ArrayList<Copy> copys;
    static long runningDvdId;
    
    /**
    * Constructor for objects of class DVD
    */
    public DVD(String newTitle, String newArtist, String newReleaseDate)
    {
        runningDvdId++;
        id = runningDvdId;
        title = newTitle;
        artist = newArtist;
        releaseDate = newReleaseDate;
        copys = new ArrayList<Copy>();
    }
    
    /**
     * Accessor and mutator methods
     */
    public long getId()
    {
        return id;
    }
    
    public void setTitle(String newTitle)
    {
        title = newTitle;
    }
        
    public String getTitle()
    {
        return title;
    }
    
    public void setArtist(String newArtist)
    {
        artist = newArtist;
    }
    
    public String getArtist()
    {
        return artist;
    }
    
    public void setReleaseDate(String newReleaseDate)
    {
        releaseDate = newReleaseDate;
    }
    
    public String getReleaseDate()
    {
        return releaseDate;
    }

    public void setCopy(String newPurchaseDate, int newPurchasePrice)
    {
        Copy newCopy = new Copy (newPurchaseDate, newPurchasePrice);
        copys.add(newCopy);
    }
    
    public Copy getCopy(long newSerialNr)
    {
        int index = 0;
        boolean found = false;
        
        while(index < copys.size() && !found)
        {
            Copy newCopy = copys.get(index);
            if(newCopy.getSerialNr() == newSerialNr)
            {
                found = true;
            }
            
            else {
                index++;
            }
        }
        
        if(found)
        {
            return copys.get(index);
        }
        
        else {
            return null;
        }
    }
    
    /**
     * returns number of copies
     */
    public int getCopies()
    {
        return copys.size();
    }
    
    /**
     * deletes a copy from the dvd
     */
    public void deleteCopy(long newSerialNr)
    {
        copys.remove(getCopy(newSerialNr));
    }
    
    /**
     * Updates a dvd from it's ID
     */
    public void updateDVD(String newTitle, String newArtist, String newReleaseDate)
    {
        setTitle(newTitle);
        setArtist(newArtist);
        setReleaseDate(newReleaseDate);
    }
    
    /**
     * Returns an ArrayList of all copies.
     */
    public ArrayList<Copy> getAllCopies()
    {
        return copys;
    }
    
    /**
     * returns the information on a dvd
     */
    public void printDVD()
    {
        System.out.println("*********************************");
        System.out.println("ID: " + id);
        System.out.println("Title: " + title);
        System.out.println("Artist: " + artist);   
        System.out.println("Release date: " + releaseDate);
        System.out.println("Copies: " + copys.size());
        System.out.println("*********************************");
    }
}